/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-11-05 14:56:05
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-04-14 16:36:30
 * @FilePath: \code\cwp-front\pc-collaboration\src\handles\common\print\fragment\index.js
 * @Description: 整合各种部分片段
 */
import sendCommon from '@/handles/common/send';
import { getCamelCase } from '@/plugins/methods';

/**
 * @description: 为所有函数增加baseInfo的store对象作为第一个参数
 * @param {Function} fn 待添加的函数
 * @return {Function} 返回柯里化之后的函数
 */
function importCTX(fn) {
    return (...arg) => fn.call(window, sendCommon.useBaseInfo, ...arg);
}

const files = require.context('./', true, /.f.js$/);
const fragmentObj = {};
files.keys().forEach((key) => {
    fragmentObj[getCamelCase(key.replace(/\.\/(.*)\.f.js/, '$1'))] = importCTX(files(key).default);
});
export default fragmentObj;
